<?php
/**
  * CLOUD
  *
  * This is not a freeware, use is subject to license terms
  * @author CLOUD DEV TEAM
  * 
  */
if (!defined('IN_CLOUD')) exit('Access Denied!');
abstract Class Controller
{
	protected $post = array();
	protected $get = array();
	protected $cookies = array();
	protected $userInfo = array();
	protected $viewModel = null;
	//protected $lang = array();
	public $pageId;
	
	public function __construct()
	{
		if ( !get_magic_quotes_gpc() )
		{
			$_POST = Common::deep_addslashes( $_POST );
			$_GET = Common::deep_addslashes( $_GET );
			$_COOKIES = Common::deep_addslashes( $_COOKIES );
			$_REQUEST = Common::deep_addslashes( $_REQUEST );
		}
		$this->get = $this->post = array_merge( $_GET , $_POST );
		$this->cokies = $_COOKIES;
		$this->viewModel = View::getInstance();
		$this->pageId = $this->get['page_id'];

		if ( !defined( 'IN_BCLOUD_ADMIN' ) )
		{
			$this->setUser();
			$this->viewModel->tplAssign(
				array(
					'userName',
					'userId',
					'nickName',
				),
				array(
					$this->userInfo['userName'],
					$this->userInfo['userId'],
					$this->userInfo['nickName'],
				)
			);
		}
	}
	
	public function setUser()
	{
		$this->userInfo['userId'] = Session::get( 'userId' ) ? Session::get( 'userId' ) : 0;
		$this->userInfo['userName'] = Session::get( 'userName' ) ? Session::get( 'userName' ) : '';
		$this->userInfo['nickName'] = Session::get( 'nickName' ) ? Session::get( 'nickName' ) : '';
	}
	
	/**
	 * 获取语言数组
	 * @param array $arr
	 */
	public static function getLang( $arr )
	{
		if ( $arr && !is_array( $arr ) )
		{
			return false;
		}
		return Lang::getLang( $arr );
	}
	
	/**
	 * 通用操作
	 */
	public function commonAction()
	{
		$this->viewModel->tplAssign( 
			array(
				'tab',
				'c',
				'a',
			) , 
			array(
				$this->get['tab'] ? $this->get['tab'] : $this->post['tab'],
				$this->get['c'] ? $this->get['c'] : $this->post['c'],
				$this->get['a'] ? $this->get['a'] : $this->post['a'],
			) 
		);
	}
	
	/**
	 * 获取分页的链接后缀
	 */
	public function getPageUrl( $sign = '&' )
	{
		if ( $this->pageId > 1 )
		{
			return $sign . 'page_id=' . $this->pageId;
		}
		return '';
	}
}